<template>
  <div class="">
    <city-header/>
    <city-search :cities = "cities"/>
    <city-list :cities = "cities" :hotCities = "hotCities" :letter = "letter"/>
    <city-alphabet :cities = "cities" @change="handleLetterChange"/>
  </div>
</template>

<script type="text/ecmascript-6">
import axios from 'axios'
import CityHeader from './pages/CityHeader'
import CitySearch from './pages/CitySearch'
import CityList from './pages/CityList'
import CityAlphabet from './pages/Alphabet'

export default {
  name: 'City',
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  methods: {
    getCityInfo () {
      axios.get('./api/city.json')
        .then(this.handleGetSucc)
    },
    handleGetSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        this.cities = res.data.cities
        this.hotCities = res.data.hotCities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style scoped lang="stylus">
</style>
